#include "StdAfx.h"
#include <CommonLib/Database.h>
#include <CommonLib/DatabaseUtils.h>

template<>
bool Database::ERROR_MESSAGE_TABLE::Load(const char* filename)
{
	assert(filename);
	mFilename = filename;
	std::ifstream file(filename);
	if (!file.is_open())
		return false;

	assert(msData.empty());
	msData.reserve(100);
	const unsigned BUFFER_SIZE = 512;
	char line[BUFFER_SIZE];
	file.getline(line, BUFFER_SIZE); // version or discard first line	
	DWORD version = ParseVersion(line);
	bool versionInfoFound = version!=0;
	if (versionInfoFound) 
	{
		file.getline(line, BUFFER_SIZE); // discard first line	
	}
	while (!file.eof())
	{
		memset(line, 0, BUFFER_SIZE);
		file.getline(line, BUFFER_SIZE);
		if (strlen(line) == 0)
			continue;
		ExpandDoubleComma(line, BUFFER_SIZE);
		fastbird::StringVector strings = fastbird::Split(line, ",\t");
		RemoveQuotes(strings);
		while(strings.size()<2)
		{
			strings.push_back(std::string());
		}

		msData.push_back(ErrorMessage());
		ErrorMessage& row = msData.back();
		int stringIdx = 0;
		row.mID = fastbird::StringConverter::parseLong(strings[0]);
		row.mMsg = strings[1];
	}
	
	return true;
}

template<>
void Database::ERROR_MESSAGE_TABLE::Save(const char* filename)
{
}